<template>
  <div>
    <div class="comment">
      <Commentdata 
      v-if="data.parent" 
      :data="data.parent" 
      @reply="reply" 
      :parentLength="parentLength-1"/>
      <div  @mouseover="isShow=true" 
        @mouseout="isShow=false">
        <div class="header">
          <div class="right">
            <img :src="$axios.defaults.baseURL +data.account.defaultAvatar" alt />
            <div class="nickname">{{data.account.nackname}}</div>
            <div class="time">2019-11-19 9:33</div>
          </div>
          <div class="left">{{parentLength}}</div>
        </div>
        <div class="fooder">
          <span>{{data.content}}</span>
          <div class="image" v-if="data.pics.length>0">
            <img v-for="(data,index) in data.pics" 
            :key="index" 
            :src="$axios.defaults.baseURL +data.url" alt="" />
          </div>
        </div>
        <div class="btn">
          <a href="#huifu" :class="{active:isShow}" @click="reply">回复</a>
        </div>
      </div>
      
    </div>
  </div>
</template>

<script>
export default {
  name: "Commentdata",
  props: {
    data: {
      type: Object,
      default: {}
    },
    parentLength: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      isShow:false,//用于回复按钮的显示隐藏
    };
  },
  methods:{
    // 注意这需要传一个对象
    reply(follow){
      if(follow.id){ 
        this.$emit('reply',{id:follow.id,nickname:follow.nickname})
      }else{
        // console.log(this.data.follow)
        if(this.data.follow){
          this.$emit('reply',{id:this.data.follow.id,nickname:this.data.account.nickname})
          
        }else{
          this.$emit('reply',{id:'',nickname:this.data.account.nickname})
        }    
      }
      
    }
  }
};

</script>

<style lang="less" scoped>
.comment {
  box-sizing: border-box;
  margin: 4px;
  border: 1px solid #e1e1e1;
  background-color: #f9f9f9;
  .header {
    padding: 10px 15px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .right {
      display: flex;
      font-size: 12px;
      color: #a69999;
      img {
        width: 16px;
        height: 16px;
        object-fit: cover;
      }
      .nickname {
        color: #666666;
        margin: 0 5px;
      }
    }
    .left {
      color: #666666;
    }
  }

  .fooder {
    box-sizing: border-box;
    padding: 10px 15px;
    color: #333;
    .image {
      display: flex;
      width: 90px;
      margin: 10px 0;
      padding: 4px;
      box-sizing: border-box;
      border: 1px dotted #e1e1e1;
      img {
        width: 80px;
        height: 80px;
        margin-right: 5px;
        object-fit: cover;
      }
    }
  }
  .btn {
    box-sizing: border-box;
    padding: 0 15px;
    width: 100%;
    height: 16px;
    margin-bottom: 5px;
    display: flex;
    justify-content: flex-end;
    font-size: 12px;
    color: #1e50a2;
    &:hover {
      text-decoration: underline solid #1e50a2;
    }
    a {
      display: none;
      &.active {
        display: block;
      }
    }
  }
  
}
</style>